package com.example.community.service.impl;

import com.example.community.entity.user;
import com.example.community.repository.userMapper;
import com.example.community.service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class userImpl implements userService {
    @Autowired
    private com.example.community.repository.userMapper userMapper;

    @Override
    public List<user> queryUser() {
        userMapper.queryUser();
        return null;
    }
    //登录
    @Override
    public user login(String username, String password) {
        user user = userMapper.queryUserByUsername(username);
        if (user != null){
            String pwd=user.getPassword();
            if (password.equals(pwd)){
                user.setPassword("密码已加密");
                return user;
            }
            return null;
        }else{
            return null;
        }
    }
    //注册
    @Override
    public user register(String username, String password) {
        user checkUser = userMapper.queryUserByUsername(username);
        if(checkUser != null){
            return null;
        }
        user user = new user();
        String userId = UUID.randomUUID().toString();
        user.setId(userId);
        user.setUsername(username);
        user.setPassword(password);
        int rowsAffected = userMapper.addUser(user);
        if(rowsAffected>0){
            user.setPassword("密码已加密");
            return user;
        }else{
            return null;

        }
    }

    @Override
    public int addUser(user user) {
        userMapper.addUser(user);
        return 0;
    }

    @Override
    public int updateUser(user user) {
        return 0;
    }

    @Override
    public int deleteUser(String id) {
        return 0;
    }
}
